﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFollow : MonoBehaviour
{
    public Transform player;
    private Vector3 targetPos; //摄像机所在位置
    Vector3 camOffset;//摄像机偏移位置

    public float angle = Mathf.PI / 4;//摄像机倾斜角
    public float distance = 100;//摄像机到目标的距离

    // Start is called before the first frame update
    void Start()
    {
        //player = GameObject.FindGameObjectWithTag("Player").transform;
        camOffset = new Vector3(0, distance * Mathf.Sin(angle), -distance * Mathf.Cos(angle));
    }

    // Update is called once per frame
    void Update()
    {
        targetPos = player.position + camOffset;
        transform.position = targetPos;//距离的插值运算

        gameObject.transform.LookAt(player);
    }
}

